SQL域错误:列不存在,设置为默认 [英] SQL domain ERROR: column does not exist, setting default

查看:142
本文介绍了SQL域错误:列不存在,设置为默认的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个域:

CREATE DOMAIN public."POSTAL_CODE"
  AS character(5)
  NOT NULL;

我尝试设置默认值:

ALTER DOMAIN public."POSTAL_CODE"
SET DEFAULT "00000";

但出现错误:


错误:列 00000不存在

ERROR: column "00000" does not exist

然后我设法使用<$ c设置默认值$ c>默认00000 ,但我认为它已强制转换为 INTEGER ,因为它显示为 0 而不是 00000 。我尝试了 character(5)[] {'0','0','0','0','0'} 也没有成功。

Then I managed to set the default value using DEFAULT 00000, but I think it was cast to INTEGER as it shows as 0 instead of 00000. I tried character(5)[] and {'0','0','0','0','0'} without success as well.

如何获取默认值作为文本而不出现错误?

How to get a default value as text and not get an error?

我使用了PostgreSQL。

I used PostgreSQL.

推荐答案

在SQL中双引号 来引用名为选择的列或表。

In SQL double quotes " are used to refer to a column or table named "select"

A 字符串常量是由单引号('),例如'This is a string'。因此,这与双引号字符(

A string constant in SQL is an arbitrary sequence of characters bounded by single quotes ('), for example 'This is a string'. So this is not the same as a double-quote character (")

因此,您必须使用如下单引号

As a result you have to use single quote like below

select * from test where old_code = '220088242'

因此,在您的情况下,应类似于以下内容

so in your case it should be like below

ALTER DOMAIN public."POSTAL_CODE"
    SET DEFAULT '00000';

这篇关于SQL域错误:列不存在,设置为默认的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆