How to use column value in where clause to determine default value

I am trying to write a query that indicates whether a column with a name sin the table has a.ta default value (this is a very large base64 row). So I tried:

SELECT 1 FROM a.t WHERE s = (
   SELECT column_default FROM information_schema.columns
   WHERE (table_schema, table_name, column_name) = ('a', 't', 's'))
   AND uname = 'joe';

Which didn’t work, so I noticed that the result from information_schema.columnshad some things that the normal query did not execute on:

SELECT column_default FROM information_schema.columns
WHERE (table_schema, table_name, column_name) = ('a', 't', 's');

column_default | 'data:image/png;base64,iVBO...QmCC'::text

Vs.

SELECT s FROM a.t WHERE uname = 'joe';

s | data:image/png;base64,iVBO...QmCC

Note the absence of quotation marks and explicit casts.
Is this really not the case? A column is sdefined as a type text.
How can I modify my query to check the correspondence between a column value and its default value?

+4
1

, ( ), - , . , . , , . SQL. ( .)

:
DEFAULT CTE UPSERT PostgreSQL 9.3
( SQL .)

DO statement .

DO
$do$
DECLARE
   _data text := 'data:image/png;base64,iVBO...QmCC';
   _answer bool;
BEGIN

EXECUTE (
   SELECT format('SELECT %s = $1', d.adsrc)
   FROM   pg_attribute a 
   JOIN   pg_attrdef   d ON (d.adrelid, d.adnum) = (a.attrelid, a.attnum)
   WHERE  a.attrelid = 'a.t'::regclass   -- schema.table
   AND    a.attname = 's'
   )
USING  _data
INTO   _answer;

RAISE NOTICE '%', answer;

END
$do$;

plpgsql. .

, , , . , .

+2

Source: https://habr.com/ru/post/1542957/


All Articles